<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>添加/修改用户</title>
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/animate.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/style.min.css?v=4.0.0" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/chosen/chosen.css" rel="stylesheet">
</head>

<body >


	<div class="ibox-content">

		<form id="subForm" method="post" class="form-horizontal"
			onsubmit="return editSysUser()">
			<input type="hidden" name="userId" id="id" value="${sysUser.userId}">
			<input type="hidden" name="pwd" id="pwd" value="${sysUser.pwd}">
			<input type="hidden" name="status" id="state" value="${sysUser.status}">
			<div class="form-group">
				<label class="col-sm-2 control-label">用户账号</label>
				<div class="col-sm-8">
					<input type="text" name="userAccount" id="tid1"
					placeholder="请输入用户账号"
						class="form-control" readonly="readonly" value="${sysUser.userAccount}" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">企业名称</label>
				<div class="col-sm-8">
					<input type="text" name="userName" placeholder="请输入企业名称"
					id="tid2"
						class="form-control" value="${sysUser.userName}" >
				</div>
			</div>
			
			
			<div class="form-group">
				<label class="col-sm-2 control-label">营业执照</label>
				<div class="col-sm-8">
					<input type="text" name="businessLicense" placeholder="请输入营业执照编号"
					id="tid5"
						class="form-control" value="${sysUser.businessLicense}" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">开户行</label>
				<div class="col-sm-8">
					<input type="text" name="openingBank" placeholder="请输入开户行"
					id="tid6"
						class="form-control" value="${sysUser.openingBank}" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">开户名称</label>
				<div class="col-sm-8">
					<input type="text" name="openingName" placeholder="请输入开户名称"
					id="tid7"
						class="form-control" value="${sysUser.openingName}" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">开户账号</label>
				<div class="col-sm-8">
					<input type="text" name="openingId" placeholder="请输入开户账号"
					id="tid8"
						class="form-control" value="${sysUser.openingId}" >
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">企业电话</label>
				<div class="col-sm-8">
					<input type="text" name="phone" placeholder="请输入企业电话"
					id="tid3"
						class="form-control" value="${sysUser.phone}" >
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">企业地址</label>
				<div class="col-sm-8">
					<input type="text" name="address" placeholder="请输入企业地址"
					id="tid4"
						class="form-control" value="${sysUser.address}" >
				</div>
			</div>
			
			
			<div class="form-group">
				<label class="col-sm-2 control-label">用户角色</label>
				<div class="col-sm-5">
					<c:forEach items="${roleList}" var="item" varStatus="i">
						
						<c:if test="${roleId!=item.roleId }">
						 <label class="checkbox-inline i-checks"><input type="radio" name="roles"
						 value="${item.roleId}" >${item.roleName}</label>
						 </c:if>
						 <c:if test="${roleId==item.roleId }">
						 <label class="checkbox-inline i-checks"><input type="radio" name="roles"
						 value="${item.roleId}" checked>${item.roleName}</label>
						 </c:if>
						  
						 
                    </c:forEach>
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<div class="col-sm-3 col-sm-offset-9">
					<button class="btn btn-primary pull-right m-t-n-xs" type="submit">保存内容</button>
				</div>
			</div>
		</form>

	</div>

	<script src="<%=request.getContextPath()%>/views/sysdefault/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/content.min.js?v=1.0.0"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/toastr/toastr.min.js"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/layer/layer.js"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/nouslider/jquery.nouislider.min.js"></script>
	<script src="<%=request.getContextPath()%>/views/sysdefault/js/demo/form-advanced-demo.min.js"></script> 
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/iCheck/icheck.min.js"></script>
    
    <script type="text/javascript">
    
    var basePath = '<%=request.getContextPath()%>';
    var hasCharge="";
    toastr.options = {
  		  "closeButton": true,
  		  "debug": false,
  		  "progressBar": true,
  		  "positionClass": "toast-top-left",
  		  "showDuration": "400",
  		  "hideDuration": "1000",
  		  "timeOut": "3000",
  		  "extendedTimeOut": "1000",
  		  "showEasing": "swing",
  		  "hideEasing": "linear",
  		  "showMethod": "fadeIn",
  		  "hideMethod": "fadeOut"
  		}
    
    //初始化页面
    $(function(){
    	
    	//复选框回显
    	/* $("input[name='roles']").each(function(i, item){
    		var roles_self = $(this);
    		var roleId = $(this).val();
    		<c:forEach items="${userRoles}" var="item" varStatus="i">
    			if(${item.id.roleId} == roleId){
    				roles_self.attr("checked", true);
    			}
        	</c:forEach>
    	}); */
    	//复选框样式
    	$(".i-checks").iCheck({
			checkboxClass : "icheckbox_square-green",
			radioClass : "iradio_square-green",
		});
    	
    });
    
    var editSysUser = function() {
    	var isTrue=validate();
		var index;
		if(isTrue==true){
		$.ajax({
			type : "POST",
			url : basePath + "/system/updateSysUser.do",
			data : $("#subForm").serialize(),
			dataType : "json",
			async: false,
			success : function(msg) {
				console.log("dfdfdfdf");
				if (msg.errCode == '1') {
					//layer.close();
					parent.layerCallBack('1');
				} else {
					toastr.error(msg.errMsg, "提示");
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				toastr.error("系统出错！", "提示");
			},
			beforeSend : function(XMLHttpRequest) {
				index = layer.load(0, {
					shade : [ 0.3, '#ccc' ]
				//0.1透明度的白色背景
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				layer.close(index);
			}
		});
		}
	  
		/* return false; */
	}
	
  //检查单位主管或者单位监管是否存在
	function validateCharge(){
		debugger;
		var deparId=$.trim($("#tid4").val());
		var userJobId=$.trim($("#tid5").val());
		var data="deparId="+deparId+"&userJobId="+userJobId;
		$.ajax({
			type : "POST",
			url : basePath + "/system/validateCharge.do",
			async: false,
			data : data,
			dataType : "json",
			success : function(msg) {
				debugger;
				if (msg.errCode == '1') {
					hasCharge="1";
				} else {
					toastr.error(msg.errMsg, "提示");
					hasCharge=false;
					return false;
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				toastr.error("系统出错！", "提示");
			}
		});
		
	}
  
  //输入空限制
	function validate(){
		
		if($.trim($("#tid1").val())==''){
			toastr.warning("请输入登录账号！", "提示");
			return false;
		}
		else if($.trim($("#tid2").val())==''){
			toastr.warning("请输入企业名称！", "提示");
			return false;
		}
		else if($.trim($("#tid3").val())==''){
			toastr.warning("请输入企业电话！", "提示");
			return false;
		}
		else if($.trim($("#tid4").val())==''){
			toastr.warning("请选择企业地址！", "提示");
			return false;
		}
	    else if($.trim($("#tid5").val())==''){
			toastr.warning("请填写营业执照！", "提示");
			return false;
		}
		else if($.trim($("#tid6").val())==''){
			toastr.warning("请填写开户行！", "提示");
			return false;
		}
		else if($.trim($("#tid7").val())==''){
			toastr.warning("请填写开户名称！", "提示");
			return false;
		}
		else if($.trim($("#tid8").val())==''){
			toastr.warning("请填写开户账号！", "提示");
			return false;
		} 
		else{
			return true;
		}
	}
	
   /*  var editSysUser = function(){
    	
    	var index;
    	
    	$.ajax({
			type : "POST",
			url : basePath + "/system/updateSysUser.do",
			data : $("#subForm").serialize(),
			dataType : "json",
			success : function(msg) { 
				if (msg.errCode == '1') {
					parent.layerCallBack('1');
				}else{
					toastr.error(msg.errMsg, "提示");
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				toastr.error("系统出错！", "提示");
			},
			beforeSend : function(XMLHttpRequest){
				index = layer.load(0, {
					  shade: [0.3,'#ccc'] //0.1透明度的白色背景
					});
			},
			complete : function(XMLHttpRequest, textStatus){
				layer.close(index);
			}
		});
	
		return false;
    } */
    //部门联动
    function deparChange(){
		debugger;
		var deparId=$.trim($("#tid4").val());
		if(deparId!=""){
			$.ajax({
				type : "POST",
				url : basePath + "/system/getDeparPid.dop",
				data : "&deparId="+deparId,
				dataType : "json",
				success : function(msg) {
					debugger;
					if (msg.errCode == '1') {
						appd(msg.data);
					} 
					else {
						toastr.error(msg.errMsg, "提示");
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					toastr.error("系统出错！", "提示");
				},
				beforeSend : function(XMLHttpRequest) {
					index = layer.load(0, {
						shade : [ 0.3, '#ccc' ]
					//0.1透明度的白色背景
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					layer.close(index);
				}
			});
			}
		else{
			toastr.error("请选择所在单位！", "提示");
			return false;
		}
			return true
		}
    
	//联动显示呈报角色
	function appd(data){
    	 debugger;
    	 document.getElementById("tid5").innerHTML = "";
    	 var temp=data
    	 for (var i=0;i<temp.length ;i++ ) 
    	 { 
    		var job=temp[i];
    		//Option(text,value)
    		document.getElementById("tid5").options.add(new Option(job,temp[i]));
    	 } 
     }
    
    </script>
    
</body>

</html>